<template>
  <div class="child">
    <h3>这是子组件,通过inject也可以获取父组件数据,当然,一般用更方便的 <b>props</b></h3>
    <div>车名:{{name}}, 价格: {{price}}万</div>
    <br>
    <grandson></grandson>
  </div>
</template>

<script>
import { inject, toRefs } from 'vue'
import grandson from './grandson.vue'

export default {
  components: { grandson },
  setup() {
    let car = inject('car')
    return {...toRefs(car)}
  },
}
</script>

<style scoped>
  .child {
    background-color: #a7e;
    padding: 5px;
  }
</style>